package com.augmentum.oes.dao.mybatis;

import java.util.List;
import org.springframework.stereotype.Repository;
import com.augmentum.oes.model.Pagination;
import com.augmentum.oes.model.Question;
import com.augmentum.oes.util.StringUtil;
import com.augmentum.oes.dao.BaseDao;
import com.augmentum.oes.dao.QuestionDao;
@Repository
public class QuestionDaoImpl extends BaseDao implements QuestionDao {
    private final static String PREFIX = Question.class.getName() + ".";

    @Override
    public void createQuestion(Question question) {
        sst.insert(PREFIX + "saveQuestion", question);
    }

    @Override
    public List<Question> queryAllQuestion() {
        return sst.selectList(PREFIX + "queryAll");
    }

    @Override
    public Question queryById(int id) {
        return sst.selectOne(PREFIX + "findById", id);
    }

    @Override
    public List<Question> queryQuestionPage(Pagination<Question> pagination) {
        String fuzzyWord = pagination.getFuzzyWord();
        pagination.setFuzzyTrans(StringUtil.shift(fuzzyWord));
        return sst.selectList(PREFIX + "questionPage", pagination);
    }

    @Override
    public void deleteQ(int id) {
        sst.delete(PREFIX + "deleteQ", id);
    }

    @Override
    public void updateQ(Question question) {
        sst.update(PREFIX + "updateQ", question);
    }

    @Override
    public int getCount(String fuzzy) {
        return sst.selectOne(PREFIX + "getCount", StringUtil.shift(fuzzy));
    }

    @Override
    public List<Question> randQ(int count) {
        return sst.selectList(PREFIX + "randQ", count);
    }
}
